// <copyright file="MenuItem.cs" company="YUIAsp.Net">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>raul popescu</author>
// <email>dev@yuiasp.net</email>
// <date>2009-01-30</date>
// <summary>YUIAsp.Net File</summary>

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YUIAspNet
{
    /// <summary>
    /// Represents a menu item.
    /// </summary>
    [ParseChildren(true)]
    [Serializable]
    [ToolboxItem(false)]
    public class MenuItem
    {
        private IList<MenuItem> _groups;
        private IList<MenuItem> _items;

        /// <summary>
        /// Initializes a new instance of the <see cref="MenuItem"/> class.
        /// </summary>
        public MenuItem(): this(null, null) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="MenuItem"/> class.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="value">The value.</param>
        public MenuItem(string text, string value)
        {
            Text = text;
            Value = value;

            Enabled = true;
            AutoPostback = false;
        }

        /// <summary>
        /// Get or set the display text/html
        /// </summary>
        public string Text { get; set; }

        /// <summary>
        /// Get or set the value of the item.
        /// </summary>
        public string Value { get; set; }

        /// <summary>
        /// Get or set the target of the hyperlink.
        /// Only took into account if the NavigateURL property has also been set.
        /// </summary>
        [DefaultValue(""), TypeConverter(typeof(TargetConverter))]
        public string Target { get; set; }

        /// <summary>
        /// Get or set the url of the control. 
        /// If this property is set, the item will act as a HyperLink
        /// </summary>
        [Bindable(true), DefaultValue(""), UrlProperty, Editor("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
        public Uri NavigateUrl { get; set; }

        /// <summary>
        /// Sub-menu items.
        /// </summary>
        [
            Category("Data"), 
            Description("Button options."),
            PersistenceMode(PersistenceMode.InnerProperty)
        ]
        public IList<MenuItem> Items 
        { 
            get
            {
                if(_items == null)
                    _items = new List<MenuItem>();
                return _items;
            }
        }

        /// <summary>
        /// Get / set the menu's groups.
        /// </summary>
        [Category("Data"), Description("Button options.")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public IList<MenuItem> Groups
        {
            get
            {
                if (_groups == null)
                    _groups = new List<MenuItem>();
                return _groups;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="MenuItem"/> is selected.
        /// </summary>
        /// <value><c>true</c> if selected; otherwise, <c>false</c>.</value>
        public bool Selected { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="MenuItem"/> is checked.
        /// </summary>
        /// <value><c>true</c> if checked; otherwise, <c>false</c>.</value>
        public bool Checked { get; set; }

        /// <summary>
        /// Gets or sets the CSS class.
        /// </summary>
        /// <value>The CSS class.</value>
        public string CssClass { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="MenuItem"/> is enabled.
        /// </summary>
        /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
        public bool Enabled { get; set; }

        /// <summary>
        /// Gets or sets the on client click.
        /// </summary>
        /// <value>The on client click.</value>
        public string OnClientClick { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether [auto postback].
        /// </summary>
        /// <value><c>true</c> if [auto postback]; otherwise, <c>false</c>.</value>
        public bool AutoPostback { get; set; }
    }
}
